package silo.dungeonbuddy;

import java.awt.Color;
import java.awt.Graphics2D;

public class TextBox
{
	private int x;
	private int y;
	private int width;
	private int height;
	private int maxTextLength;
	private boolean visible;
	private boolean selected;
	private String text;
	private String name;
	
	public TextBox(String eName, int eX, int eY, int eWidth, int eHeight, boolean eVis, int eMaxTextLength)
	{
		x=eX;
		y=eY;
		width=eWidth;
		height=eHeight;
		visible=eVis;
		maxTextLength=eMaxTextLength;
		selected=false;
		text="";
		name = eName;
	}//Constructor
	
	public void draw(Graphics2D g)
	{
		if(visible)
		{
			if(selected)
			{
				g.setColor(Color.yellow);
				g.fillRect(x-2,y-2,width+4,height+4);
			}
			g.setColor(Color.white);
			g.fillRect(x,y,width,height);
			//Horizontal shade
			g.setColor(Color.darkGray);
			g.drawLine(x,y,x+width-1,y);
			g.setColor(Color.gray);
			g.drawLine(x,y+1,x+width-1,y+1);
			g.setColor(Color.lightGray);
			g.drawLine(x,y+2,x+width-1,y+2);
			//Vertical shade
			g.setColor(Color.darkGray);
			g.drawLine(x,y,x,y+height-1);
			g.setColor(Color.gray);
			g.drawLine(x+1,y+1,x+1,y+height-1);
			g.setColor(Color.lightGray);
			g.drawLine(x+2,y+2,x+2,y+height-1);
			//Text
			g.setColor(Color.black);
			g.drawString(text, x+2, y+height-2);
			//Label
			if(!name.startsWith("txt"))
			{
				g.drawString(name, x, y-1);
			}
		}
	}//draw
	
	//GETTERS
	public int getX()
	{
		return x;
	}
	public int getY()
	{
		return y;
	}
	public int getWidth()
	{
		return width;
	}
	public int getHeight()
	{
		return height;
	}
	public boolean getVisible()
	{
		return visible;
	}
	public boolean getSelected()
	{
		return selected;
	}
	public String getText()
	{
		return text;
	}
	public String getName()
	{
		return name;
	}
	
	//SETTERS
	public void setX(int eX)
	{
		x=eX;
	}
	public void setY(int eY)
	{
		y=eY;
	}
	public void setWidth(int eWidth)
	{
		width=eWidth;
	}
	public void setHeight(int eHeight)
	{
		height=eHeight;
	}
	public void setVisible(boolean eVis)
	{
		visible = eVis;
	}
	public void setSelected(boolean eSelected)
	{
		selected=eSelected;
	}
	public void setText(String eText)
	{
		if((eText.length()<maxTextLength)||(maxTextLength==0))
		{
			text=eText;
		}
	}
	public void setName(String eName)
	{
		name = eName;
	}
}//class TextBox